<?php

use Biz\model\GoodsTestActivity\FineGoodsModel;
use Biz\model\GoodsTestActivity\FineGoodsMsgModel;
use Biz\service\GoodsTestActivity\FineGoodsService;

/**
 *活动列表
 * Class ListAction
 */
class ListAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_NOTHING;
    private const PAGE_SIZE = 20;

    public function main()
    {
        //获取消息氛围列表
        $where["LIMIT"] = self::PAGE_SIZE;
        $where['ORDER'] = ['addtime' => "DESC"];
        $where['msg_type'] = [FineGoodsMsgModel::MSG_SUCCESS, FineGoodsMsgModel::MSG_APPLY];
        $msg_list = FineGoodsService::getMsgListByWhere($where);

        $data['msg_list'] = array_values($msg_list);

        //获取活动列表
        $act_field = [
            'id',
            'type',
            'brand_id',
            'brand_name',
            'basic_title',
            'activity_title',
            'goods_num',
            'goods_worth',
            'goods_max_worth',
            'schedule_start_time',
            'schedule_end_time',
            'activity_state',
            'basic_id',
            'cover_img',
            'report_num',
            'evaluation_id',
            'category_tag_id'
        ];
        $act_list = FineGoodsService::getActIngList($act_field);
        $act_list = FineGoodsService::getFineGoodsPv($act_list);
        //评测置顶
        $evaluationActList = [];
        foreach ($act_list as $key => $row) {
            if ($row['type'] == FineGoodsModel::TYPE_EVALUATION) {
                $evaluationActList[] = $row;
                unset($act_list[$key]);
            }
        }
        $data['act_list'] = array_merge($evaluationActList, $act_list);
        //获取体验中列表
        $act_learn_list = FineGoodsService::getActLearnList($act_field);
        $act_learn_list = FineGoodsService::getFineGoodsPv($act_learn_list, false);
        $data['act_learn_list'] = $act_learn_list;
        foreach (FineGoodsModel::CATEGORY_TAG_MAP as $type => $tag) {
            $data['category_tag'][] = [
                'id' => $type,
                'title' => $tag
            ];
        }

        $this->setSuccess($data);
    }

}


